package com.example.controller;


import com.example.common.result.Result;
import com.example.entity.vo.SubEmpVO;
import com.example.service.SubEmpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/subemp")
@Slf4j
@Api(tags = "人员-项目相关接口")
public class SubEmpController {

    @Autowired
    private SubEmpService subEmpService;

    /**
     * 项目获取人员列表
     * @param subId
     * @return
     */
    @GetMapping("/get")
    @ApiOperation("项目获取人员列表")
    public Result<List<SubEmpVO>> getEmployee(@RequestParam int subId){
        log.info("项目获取人员列表:{}",subId);
        List<SubEmpVO> subEmpVOS = subEmpService.getEmployee(subId);
        return Result.success(subEmpVOS);
    }

    /**
     * 项目新增人员
     * @param subEmpVO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("项目新增人员")
    public Result addEmployee(@RequestBody SubEmpVO subEmpVO){
        log.info("项目新增人员：项目id：{}，人员id{}",subEmpVO.getProjectsId(),subEmpVO.getEmployeeId());
        subEmpService.addEmployee(subEmpVO);
        return Result.success();
    }

    /**
     * 删除项目人员
     * @param subEmpVO
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("删除项目人员")
    public Result deleteEmployee(@RequestBody SubEmpVO subEmpVO){
        log.info("项目删除人员：项目id：{}，人员id{}",subEmpVO.getProjectsId(),subEmpVO.getEmployeeId());
        subEmpService.deleteEmployee(subEmpVO);
        return Result.success();
    }

    /**
     * 人员获取项目
     * @param empId
     * @return
     */
    @GetMapping("/getP")
    @ApiOperation("人员获取项目")
    public Result<List<SubEmpVO>> getSub(@RequestParam int empId){
        log.info("人员获取项目列表:{}",empId);
        List<SubEmpVO> subEmpVOS = subEmpService.getSub(empId);
        return Result.success(subEmpVOS);
    }

}
